#encoding=utf8
'''
Created on 2012-10-18

@author: Administrator
'''
from DbOperator import DbOperator
from SysUser import SysUser
from pub import Func
from pub.Config import Config
class SysUserModel(DbOperator):
    '''
    classdocs
    '''


    def __init__(self):
        '''
        Constructor
        '''
        DbOperator.__init__(self)
    def login(self,sUserName,sUserPass):
        '''
        用户登录
        @param userName:string
        @param userPass:string
        @return:SysUser  
        '''
        aParam = {
                  Config.S_TABLE:SysUser.TABLE_NAME,
                  Config.S_SEARCHFIELDS:"*",
                  Config.S_SEARCHCONDITION:"`%s`='%s'  AND `%s`=1 " % (SysUser.USERNAME,sUserName,SysUser.LOGINSTATE),
                  Config.S_RESULTROW:1,
        }
        result = self.getFieldByCondition(aParam) 
        if(not result):
            return (Config.I_USER_NOT_FOUND,None)
        if(sUserPass==result[SysUser.USERPASS]):
            oUser = SysUser()
            oUser.set_id(result[SysUser.USERID])  
            oUser.set_user_name(result[SysUser.USERNAME])  
            oUser.set_user_pass(result[SysUser.USERPASS])  
            oUser.set_user_email(result[SysUser.USEREMAIL])  
            oUser.set_user_tel(result[SysUser.USERTEL])  
            oUser.set_created(result[SysUser.CREATED])            
            return (Config.I_USER_LOGIN_OK,oUser)
        else:
            return (Config.I_USER_PASSWORD_ERROR,None)     
if __name__=="__main__":
    mSysUser = SysUserModel()
    print mSysUser.login("geminiblue", "123456")   